<?php
namespace App\Shop\Forms\Cash;

use App\Admin\Repositories\GoodOrderDetail;
use App\Models\CashOrder;
use App\Models\GoodOrder;
use App\Models\ShopUser;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Grid;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class HandleCashOrder extends Form implements LazyRenderable
{
    use LazyWidget;

    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
         $res = 0;
         if ($input){
             try {
                 $amount = $input['amount'];
                 $shopUser = auth("shop")->user();
                 $order = new CashOrder();

//                 $res = $order->save();
             }catch (ModelNotFoundException|Exception $e){
                 return $this->response()->error($e->getMessage())->refresh();
             }
         }
         return $this->response()->success($res?'保存成功.':'暂无修改.')->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->display("money","可提现金额");
        $this->display("used_money","已可提现金额");
        $this->currency("amount","申请提现金额");
    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {
        return $this->getDefault();
    }

    protected function getDefault(){
        $shopUser = auth("shop")->user();
        return collect($shopUser)->toArray();
    }
}
